"""数据库系统异常定义模块

包含数据库管理系统各个组件的异常类定义
"""

# ============================================================================
# 通用异常 (Common Exceptions)
# ============================================================================

class CacheFullException(RuntimeError):
    """缓存已满异常"""
    def __init__(self, message="Cache is full!"):
        super().__init__(message)

class FileExistsException(RuntimeError):
    """文件已存在异常"""
    def __init__(self, message="File already exists!"):
        super().__init__(message)

class FileNotExistsException(RuntimeError):
    """文件不存在异常"""
    def __init__(self, message="File does not exists!"):
        super().__init__(message)

class FileCannotRWException(RuntimeError):
    """文件无法读写异常"""
    def __init__(self, message="File cannot read or write!"):
        super().__init__(message)

# ============================================================================
# 磁盘管理器异常 (Disk Manager Exceptions)
# ============================================================================

class BadLogFileException(RuntimeError):
    """日志文件损坏异常"""
    def __init__(self, message="Bad log file!"):
        super().__init__(message)

class MemTooSmallException(RuntimeError):
    """内存过小异常"""
    def __init__(self, message="Memory too small!"):
        super().__init__(message)

class DataTooLargeException(RuntimeError):
    """数据过大异常"""
    def __init__(self, message="Data too large!"):
        super().__init__(message)

class DatabaseBusyException(RuntimeError):
    """数据库繁忙异常"""
    def __init__(self, message="Database is busy!"):
        super().__init__(message)

# ============================================================================
# 事务管理器异常 (Transaction Manager Exceptions)
# ============================================================================

class BadXIDFileException(RuntimeError):
    """事务ID文件损坏异常"""
    def __init__(self, message="Bad XID file!"):
        super().__init__(message)

# ============================================================================
# 版本管理器异常 (Version Manager Exceptions)
# ============================================================================

class DeadlockException(RuntimeError):
    """死锁异常"""
    def __init__(self, message="Deadlock!"):
        super().__init__(message)

class ConcurrentUpdateException(RuntimeError):
    """并发更新异常"""
    def __init__(self, message="Concurrent update issue!"):
        super().__init__(message)

class NullEntryException(RuntimeError):
    """空条目异常"""
    def __init__(self, message="Null entry!"):
        super().__init__(message)

# ============================================================================
# 表管理器异常 (Table Manager Exceptions)
# ============================================================================

class InvalidFieldException(RuntimeError):
    """无效字段类型异常"""
    def __init__(self, message="Invalid field type!"):
        super().__init__(message)

class FieldNotFoundException(RuntimeError):
    """字段未找到异常"""
    def __init__(self, message="Field not found!"):
        super().__init__(message)

class FieldNotIndexedException(RuntimeError):
    """字段未建索引异常"""
    def __init__(self, message="Field not indexed!"):
        super().__init__(message)

class InvalidLogOpException(RuntimeError):
    """无效逻辑操作异常"""
    def __init__(self, message="Invalid logic operation!"):
        super().__init__(message)

class InvalidValuesException(RuntimeError):
    """无效值异常"""
    def __init__(self, message="Invalid values!"):
        super().__init__(message)

class DuplicatedTableException(RuntimeError):
    """重复表异常"""
    def __init__(self, message="Duplicated table!"):
        super().__init__(message)

class TableNotFoundException(RuntimeError):
    """表未找到异常"""
    def __init__(self, message="Table not found!"):
        super().__init__(message)

# ============================================================================
# 解析器异常 (Parser Exceptions)
# ============================================================================

class InvalidCommandException(RuntimeError):
    """无效命令异常"""
    def __init__(self, message="Invalid command!"):
        super().__init__(message)

class TableNoIndexException(RuntimeError):
    """表无索引异常"""
    def __init__(self, message="Table has no index!"):
        super().__init__(message)

# ============================================================================
# 传输层异常 (Transport Exceptions)
# ============================================================================

class InvalidPkgDataException(RuntimeError):
    """无效包数据异常"""
    def __init__(self, message="Invalid package data!"):
        super().__init__(message)

# ============================================================================
# 服务器异常 (Server Exceptions)
# ============================================================================

class NestedTransactionException(RuntimeError):
    """嵌套事务异常"""
    def __init__(self, message="Nested transaction not supported!"):
        super().__init__(message)

class NoTransactionException(RuntimeError):
    """无事务异常"""
    def __init__(self, message="Not in transaction!"):
        super().__init__(message)

# ============================================================================
# 启动器异常 (Launcher Exceptions)
# ============================================================================

class InvalidMemException(RuntimeError):
    """无效内存异常"""
    def __init__(self, message="Invalid memory!"):
        super().__init__(message)